package com.example.jin.myapplication;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

/**
 * Created by jin on 2016/6/10.
 */
public class PictureUtils {
    public static Bitmap getScaledBitmap(String path,int w,int h){
        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inJustDecodeBounds=true;

        Bitmap bitmap= BitmapFactory.decodeFile(path,options);
        Log.i("main","path:"+path);


            int width=options.outWidth;
            int height=options.outHeight;
            options=new BitmapFactory.Options();
            if(w<width||h<height) {
                float r1 = (float) width / w;
                float r2 = (float) height / h;
                int ratio = Math.round(r1 > r2 ? r1 : r2);
                options.inJustDecodeBounds = false;
                options.inScaled = true;
                options.inSampleSize = ratio;
            }
            bitmap=BitmapFactory.decodeFile(path,options);

        return bitmap;
    }
}
